#ifndef LIBDLM_H
#define LIBDLM_H

#include <map>
#include <vector>
#include <unistd.h>

/**
 * Status returned from DLM_init
 */
const int DLM_INIT_FAIL_STATUS = -1;
const int DLM_INIT_OK_CLIENT_STATUS = 0;
const int DLM_INIT_OK_COORDINATOR_STATUS = 1;

const int DLM_RETURN_OK = 0;
const int DLM_RETURN_FAIL = 1;

const char MSG_FLAG_LOCK = 0;
const char MSG_FLAG_UNLOCK = 1;
const char MSG_FLAG_TRYLOCK = 2;
const char MSG_FLAG_QUIT = 3;

const int CLIENT_SERVER_PACKET_LENGTH = sizeof(pid_t) + sizeof(char) + 2 * sizeof(int) + sizeof(long);

const int CR = 0; //concurrent read
const int CW = 1; //concurrent write
const int PR = 2; //protected read
const int PW = 3; //protected write
const int EX = 4; //exclusive

const bool PRIVILEGES[5][5] = { { true,  true,  true,  true,  false },
                                { true,  true,  false, false, false },
                                { true,  false, true,  false, false },
                                { true,  false, false, false, false }, 
                                { false, false, false, false, false } };

int DLM_init(int client_num);

int DLM_lock(int resource_id, int lock_type, long timeout);

int DLM_unlock(int resource_id);

int DLM_trylock(int resource_id, int lock_type);

int send_msg(char msgType, pid_t pid, int resource_id, int lock_type, long timeout);

int read_msg(char *msgType, int* resource_id, int* lock_type, long* timeout);

std::vector<pid_t> get_client_pid_vector();

void DLM_cleanup();

int getClientToServerPipe();
int getServerToClientPipe();

#endif

